home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Context
/
Context.cp
next >
Wrap
Text File
|
1997-06-28
|
2KB
|
126 lines
// Context.cp
#ifndef Context_h
#include "Context.h"
#endif
#ifndef Assert_h
#include "Assert.h"
#endif
#ifndef ContextMaintainer_h
#include "ContextMaintainer.h"
#endif
Context *Context::current = 0;
Context::Context()
: parent( current ),
users( 0 ),
active( true )
{
current = this;
if ( parent != 0 )
{
Assert( parent->users < maxuint32 );
parent->users++;
}
}
Context::~Context()
{
Assert( users == 0 );
Assert( !active );
if ( parent != 0 )
{
Assert( parent->users > 0 );
parent->users--;
}
ContextMaintainer::StopMaintaining( this );
}
void Context::Activate()
{
Assert( !active );
Assert( parent == current );
Enter();
active = true;
current = this;
}
void Context::Deactivate()
{
Assert( active );
Assert( this == current );
if ( useAssertions )
Check();
Leave();
active = 0;
current = parent;
}
void Context::BeCurrent()
{
BeActive();
while ( current != this )
{
Assert( current != 0 );
current->Deactivate();
}
}
void Context::BeActive()
{
if ( active )
return;
if ( parent == 0 )
LeaveAll();
else
parent->BeCurrent();
Activate();
}
void Context::LeaveAll()
{
while ( current != 0 )
current->Deactivate();
}
void Context::BeInactive()
{
while( active )
{
Assert( current != 0 );
current->Deactivate();
}
}
void Context::CheckActive()
{
for ( Context *c = current; c != 0; c = c->parent )
c->Check();
}
void Context::ReenterActive()
{
if ( current != 0 )
current->ReenterWithParents();
}
void Context::ReenterWithParents()
{
if ( parent != 0 )
parent->ReenterWithParents();
Reenter();
}
void Context::Set( Context *c )
{
if ( c == 0 )
LeaveAll();
else
c->BeCurrent();
}